package com.example.inteviewwhy.dao;

import com.example.inteviewwhy.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserRepository extends JpaRepository<User,Long> {

    // 添加、修改用户
    @Override
    <S extends User> S saveAndFlush(S entity);

    // 查询用户列表
    @Query("select new User(uid,uname,age,sex) from User where uname like %?1%")
    List<User> findAll(@Param("uname") String uname);

    // 查询用户详情
    @Query("select new User(uid,uname,age,sex) from User where uid = ?1")
    User findDetail(Long uid);

    // 删除用户信息
    @Override
    void delete(User entity);


}
